import React from "react";
// 父组件
class fatherSon extends React.Component {
    state = {
        name: "刘凯欣",
        parmsName:"",
    }
    // 接受组件传递过来得方法
    getChildMsg = (data) => {
        // console.log("接受子组件传递过来得数据:", data)
        this.setState({
            parmsName:data
        });
    }
    render() {
        return (
            <div>
                <Son name={this.state.name} getMsg={this.getChildMsg}></Son>
                <p>由子组件传递过来的数据为：{this.state.parmsName}</p>
            </div>
        )
    }
}

// 子组件
class Son extends React.Component {
    state={
        sonName:"刘艹艹"
    }
    // 点击后将子组件中得值已参数得形式传递给父组件
    handleClick = ()=>{
        this.props.getMsg(this.state.sonName)
    }
    render() {
        console.log(this.props)
        return (
            <div>
                <p>子组件显示{this.props.name}</p>
                <button onClick={this.handleClick}>点击我给父组件传递数据</button>
            </div>
        )
    }
}

export default fatherSon